/*
 * jcr.h
 *
 *  Created on: Feb 15, 2012
 *      Author: fumin
 */

#ifndef Jcr_H_
#define Jcr_H_

#include "destor.h"
#include "recipe/recipestore.h"

#define JCR_STATUS_INIT 1
#define JCR_STATUS_RUNNING 2
#define JCR_STATUS_DONE 3
/* job control record */
struct {
	int32_t id;
	/*
	 * The path of backup or restore.
	 */
	sds path;
	int status;
	int32_t file_num;
	int64_t data_size;
	int64_t unique_data_size;
	int64_t delta_data_size;
	int32_t chunk_num;
	int32_t unique_chunk_num;
	int32_t delta_chunk_num;
	int32_t zero_chunk_num;
	int64_t zero_chunk_size;
	int32_t rewritten_chunk_num;
	int64_t rewritten_chunk_size;
    
    int32_t rewritten_base_chunk_num;
    int32_t rewritten_base_chunk_size;

    int32_t base_chunk_num_in_ver1;
    int32_t base_container_in_ver1;
   
    int64_t container_num_before_backup;
    int64_t container_num_stored;
    int64_t container_num_after_backup;

    /* 
     * container_num_now_stored used for determining
     * the container_id has been written to disk array
     * container_num_now_written used for determining
     * the container_id has been written to disk
     */
    int64_t container_num_now_written;
    int64_t container_num_now_stored; 

    double percent_base_container_in_ver1;

    int32_t total_container_num_referred;
	int32_t sparse_container_num;
	int32_t inherited_sparse_num;
        
    int32_t base_chunk_referred;
    int32_t base_container_referred;
    	
    int32_t container_num_of_first_backup;
    int32_t base_container_in_sparse;
    int32_t base_chunk_in_sparse_container;

    int64_t unique_containers_in_restore;

	struct backupVersion* bv;

	double total_time;
	/*
	 * the time consuming of six dedup phase
	 */
	double read_time;
	double chunk_time;
	double hash_time;
	double dedup_time;
	double rewrite_time;
	double filter_time;
	double write_time;
    double super_feature_time;

    double matching_time;
    double delta_time;

	double read_recipe_time;
	double read_chunk_time;
	double write_chunk_time;

	int32_t read_container_num;

    int64_t base_cache_hit;
    int64_t base_cache_miss;

    int64_t base_container_read;

    int sparse_baseExist_rewritten_num;

    int64_t last_container_number_of_backup;

    int64_t containers_to_restore;
    double predict_restore_speed_factor;
    int32_t dedup_delta_chunks;
    int64_t total_sf_num;
    int64_t freed_delta_number;
    int64_t number_of_chunks_has_delta;
    int32_t number_of_ofc_chunks;
    int32_t duplicate_has_delta;
    int32_t noduplicate_has_outoforder;
    int64_t delta_compression_times;
    int32_t only_base_referenced_containers;
    int64_t read_normal_chunks;
    int64_t read_base_chunks;
    int64_t hit_normal_chunks;
    int64_t hit_base_chunks;
    int64_t hit_sparse_base_cid;
    int64_t miss_sparse_base_cid;

    int64_t slack_content;
    int64_t delta_compressed_size;
    int64_t size_before_compressed;
    int unproper_delta_comp_num;
    int64_t total_size_for_similar_detection;
    int64_t total_compressed_size;
	int64_t total_size_for_deltacompression;
    int64_t chunk_num_for_simi_dete;

    int64_t sketch_replace_time;
    int64_t sketch_index_item_num;

	int64_t stored_data_size;

	int sf_matched_number;
	int multi_matched_chunk_number;
	int multi_matched_diff_number;
} jcr;

void init_jcr(char *path);
void init_backup_jcr(char *path);
void init_restore_jcr(int revision, char *path);

#endif /* Jcr_H_ */
